
#include <iostream>
#include <cc++/thread.h>

using namespace ost;
using namespace std;

class MyThread: public Thread
{
public:
	MyThread(int id, ThreadKey *k): _id(id), _k(k) {}
	void run();
	int _id;
	ThreadKey* _k;
};

void MyThread::run()
{
	int *i = new int;
	*i = _id;
	cout << "thread " << _id << "start" << endl;
	while(1)
	{
		_k->setKey(i);
		sleep(1000);
		int* p=(int*)_k->getKey();
		cout << "thread " << _id << ":" << *p << endl;
	}	
}



int main()
{
	ThreadKey key;
	MyThread t1(1, &key), t2(2, &key);
	
	char* p="1234";
	key.setKey(p);
	
	cout << (char*)key.getKey() << endl;
		
	t1.start();
	t2.start();
	int i=0;
	while(i<1000)
	{
		key.setKey(p);
		Thread::sleep(100);
		i++;
	}
	cout << "done" << endl;
	
	t1.join();
	
	return 0;
}

